package com.superitem.school.controller;

import com.github.pagehelper.PageInfo;
import com.superitem.school.pojo.Goods;
import com.superitem.school.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;


@Controller
@RequestMapping("goods")
public class GoodsController {

    @Autowired
    public GoodsService goodsService;

    @Value("${page.size}")
    String pageSize;

    @RequestMapping("show_all_goods/{pageNum}")
    public String ShowAllGoods(@PathVariable("pageNum")Integer pageNum, Model model){
        PageInfo<Goods> pageInfo = goodsService.showAllGoods(pageNum, Integer.valueOf(pageSize));
        System.out.println(pageInfo.toString());
        model.addAttribute("pageInfo", pageInfo);
        return "goods/showgoods";
    }

    @RequestMapping("show_one_good/{id}")
    public String ShowOneGood(@PathVariable("id")Integer id, Model model){
        Goods good = goodsService.showOneGood(id);
        System.out.println(good);
        model.addAttribute("good", good);
        return "goods/showOne";
    }
}
